package cn.edu.nju.oraldefense.action;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import cn.edu.nju.oraldefense.model.Graduate;
import cn.edu.nju.oraldefense.service.GraduateService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 获取学生信息，如果是登录学生，直接从session中获取，否则需要通过 id查询
 * 
 * @author ZhangZu
 * 
 */
public class GraduateInfoAction extends ActionSupport {

	private int id;
	private Graduate graduate;
	private GraduateService graduateService;

	@JSON(serialize = false)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Graduate getGraduate() {
		return graduate;
	}

	public void setGraduate(Graduate graduate) {
		this.graduate = graduate;
	}

	@JSON(serialize = false)
	public GraduateService getGraduateService() {
		return graduateService;
	}

	@Resource
	public void setGraduateService(GraduateService graduateService) {
		this.graduateService = graduateService;
	}

	public String selfExecute() {
		ActionContext ctx = ActionContext.getContext();
		graduate = (Graduate) ctx.getSession().get("graduate");
		return SUCCESS;
	}

	public String execute() {
		graduate = graduateService.getById(id);
		return SUCCESS;
	}

}
